package logic

import (
	"log"
	"mssgserver/constant"
	"mssgserver/db"
	"mssgserver/server/common"
	"mssgserver/server/game/model"
	"mssgserver/server/game/model/data"
)

//角色建筑

var RoleBuildService = &roleBuildService{}

type roleBuildService struct {
}

/*
*
获取角色建筑
*/
func (s *roleBuildService) GetBuilds(rid int) ([]model.MapRoleBuild, error) {
	mr := &data.MapRoleBuild{}
	mrs := make([]data.MapRoleBuild, 0)
	err := db.Engine.Table(mr).Where("rid=?", rid).Find(&mrs)
	if err != nil {
		log.Println("GetBuilds查询数据库失败")
		return make([]model.MapRoleBuild, 0), common.New(constant.DBError, "GetBuilds查询数据库失败")
	}
	roleBuilds := make([]model.MapRoleBuild, 0)
	for _, roleBuild := range mrs {
		roleBuilds = append(roleBuilds, roleBuild.ToModel().(model.MapRoleBuild))
	}
	return roleBuilds, nil
}
